import java.util.ArrayList;
import java.util.List;

public class Solution38 {
    /**
     *
     */
    public String countAndSay(int n) {
        String s = "1";
        for (int i = 1; i < n; i++) {
            char[] chars = s.toCharArray();
            StringBuilder sb = new StringBuilder();
            int len = 1;
            for (int j = 1; j < chars.length; j++) {
                if (chars[j] == chars[j - 1]) {
                    len++;
                } else {
                    sb.append(len).append(chars[j - 1]);
                    len = 1;
                }
            }
            s = sb.append(len).append(chars[chars.length - 1]).toString();
        }
        return s;
    }
}
